<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Layui</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="/addons/hc_answer/template/plugins/layui/css/layui.css" media="all" />
	</head>

	<body>
		<div style="margin: 15px;">
			<fieldset class="layui-elem-field">
				<legend>导入题目</legend>
			
				<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
					<div class="layui-tab-content" >
						<!-- 基础设置 开始-->
						<form class="layui-form" action="" id="form" enctype="multipart/form-data">
							<div class="layui-form-item">
							      <label class="layui-form-label">题目分组</label>
							      <div class="layui-input-inline">
							        <select name="type_id">
							          <option value="">请选择分组</option>
							          {loop $cate $item}
							          <optgroup label="{$item['name']}">
							          	{loop $item['children'] $v}
							            <option value="{$v['id']}" >{$v['name']}</option>
							          	{/loop}
							          </optgroup>
							          {/loop}
							        </select>
							    </div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">难易程度</label>
							    <div class="layui-input-block">
							      <input type="radio" name="easy" value="1" title="简单" checked="checked" >
							      <input type="radio" name="easy" value="2" title="一般" >
							      <input type="radio" name="easy" value="3" title="复杂" >
							    </div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">选择文件</label>
							    <div class="layui-input-block">
							    	<input type="file" name="excel" lay-type="file" class="layui-upload-file">
							    	<input type="hidden" name="excels" id="excels" value="">
							    	<a style="color:blue" href="{$_W['siteroot']}addons/hc_answer/excel/example.xls">下载模板</a>
							    </div>
							</div>

							<div class="layui-form-item">
							    <div class="layui-input-block">
							      <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="demo1">立即提交</button>
							      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
							    </div>
							</div>

						</form>
						<!-- 题目设置 结束-->
					</div>
				</div>	
			</fieldset>
		</div>

		<script type="text/javascript" src="/addons/hc_answer/template/plugins/layui/layui.js"></script>
		<script>
			layui.use(['form','upload','layer'], function() {
				var $ = layui.jquery,
				form = layui.form();
				form.render();
				layui.upload({
				  url: '{php echo $this->createWebUrl("Uploadexcel");php}'
				  ,type: 'file'
				  ,success: function(res){
				    $("#excels").val(res.path);
				  }
				});
				
				form.on('submit(demo1)', function(data) {
					$.ajax({
			            url:"{php echo $this->createWebUrl('librarydo',array('act'=>import));php}",
			            data:$('#form').serialize(),
			            type:"post",
			            dataType:"json",
			            success:function(data){
			            	if(data.code=='1'){
			                	layer.alert(data.msg, {icon: 6},function(index){
			                		var index = parent.layer.getFrameIndex(window.name);
			                		parent.layer.close(index)
			                	});
								
			            	}else{
			                	layer.alert(data.msg, {icon: 5});
			            	}
			            },
			            error:function(data){
			                layer.alert('请稍后重试', {icon: 5});
			            }
			        });
					return false;
				});
				
			});
		</script>

	</body>

</html>